package com.cs.controller;

import com.cs.anno.Log;
import com.netflix.discovery.converters.Auto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sys")
@Api(tags = "登出的管理接口")
public class SysLogOutController {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @PostMapping("/logout")
    @ApiOperation(value = "登出的接口")
    @Log(value = "登出")
    public ResponseEntity<String> logout(){
        OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) SecurityContextHolder.getContext().getAuthentication().getDetails();
        String tokenValue = details.getTokenValue();
        //登出删除登录的token
        Boolean delete = redisTemplate.delete("oauth:jwt:" + tokenValue);
        return ResponseEntity.ok("登出成功");
    }
}
